<!--
 * @Author: JiraiyaChen 979526234@qq.com
 * @Date: 2025-06-23 10:59:33
 * @LastEditors: JiraiyaChen 979526234@qq.com
 * @LastEditTime: 2025-06-23 14:20:22
 * @Description: 评标报告查看 （一类）
-->

<template>
  <ClDialog v-bind="$attrs" :title="getTitle" width="1390px">
    <UnitTable v-if="loaded" :table-data="tableData" :column-list="columnList" @judge-info="judgeInfo" />
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="onSure">确定</el-button>
      </span>
    </template>
  </ClDialog>
  <JudgeInfoDialog v-if="hookVisible" v-model="hookVisible" :info="dialogInfo" :type="type" @at-close="onCloseDialog" />
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import UnitTable from './UnitTable.vue'
import JudgeInfoDialog from './JudgeInfoDialog.vue'
import { getItemSummary } from '@/api/scoring-details-summary'
onMounted(async () => {})

const onSure = async () => {
  emit('atClose')
}
const { type, hookVisible, dialogInfo, onOpenDialog, onCloseDialog } = useDialog(null)
const judgeInfo = async (column: any) => {
  type.value = `${column.judgeName}-评标汇总查看`
  onOpenDialog({ judgeId: column.judgeId, itemIds: [props.info.itemId] })
}
onMounted(() => {
  init()
})

const loaded = ref(false)
const tableData = ref([])
const columnList = ref<any[]>([])
const init = async () => {
  try {
    loaded.value = false
    const projectId = useProjectInfoStore().projectInfo.id
    const res: any = await getItemSummary({
      projectId,
      itemId: props.info.itemId
    })
    tableData.value = res
    if (res.length > 0) {
      columnList.value = res[0].judgeScoreList
    }
    loaded.value = true
  } catch (error) {
    console.log('🐷 🐽 init 🐽 error👉👉👉', error)
    loaded.value = true
  }
}

const getTitle = computed(() => {
  return props.type
})

interface infoType {
  [props: string]: any
}
const props = defineProps<{ info: infoType; type: string }>()

const emit = defineEmits<{
  (e: 'atClose', str?: string | undefined): void
}>()
</script>

<style scoped lang="scss"></style>
